from django.db import models


# Create your models here.
class Users(models.Model):
    avatar = models.CharField(max_length=100, verbose_name='头像')
    username = models.CharField(max_length=20, unique=True, verbose_name='用户名', null=True)
    password = models.CharField(max_length=30, verbose_name='密码', null=True)
    status_choice = (
        (0, '正常使用'),
        (1, '已禁用')
    )
    status = models.BooleanField(choices=status_choice, default=0, verbose_name='用户状态', null=True, blank=True)
    is_login_choice = status_choice = (
        (0, '未登录'),
        (1, '已登录')
    )
    is_login = models.BooleanField(choices=is_login_choice, default=0, verbose_name='登录状态', null=True, blank=True)
    mail = models.EmailField(null=True, blank=True, verbose_name='邮箱')
    phone = models.CharField(max_length=15, null=True, blank=True, verbose_name='手机号')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间', null=True, blank=True)
    remark = models.CharField(max_length=256, null=True, blank=True, verbose_name='简介')

    class Meta:
        verbose_name_plural = '用户表'


class Token(models.Model):
    token = models.CharField(unique=True, max_length=200)
    user = models.ForeignKey('Users', on_delete=models.CASCADE)
    outTime_choice = (
        (0, '未过期'),
        (1, '已过期')
    )
    outTime = models.BooleanField(choices=outTime_choice, default=0)
    update_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间', null=True, blank=True)


class Favorites(models.Model):
    id = models.CharField(max_length=20, primary_key=True)
    name = models.CharField(max_length=20, verbose_name='收藏夹名')
    user = models.ForeignKey('Users', on_delete=models.CASCADE)

    class Meta:
        verbose_name_plural = '大收藏夹'


class MFavorites(models.Model):
    id = models.CharField(max_length=20, primary_key=True)
    name = models.CharField(max_length=20, verbose_name='收藏夹名')
    favorite = models.ForeignKey('Favorites', on_delete=models.CASCADE, verbose_name='属于', to_field='id')

    class Meta:
        verbose_name_plural = '中收藏夹'


class SFavorites(models.Model):
    id = models.CharField(max_length=20, primary_key=True)
    name = models.CharField(max_length=20, verbose_name='收藏夹名')
    favorite = models.ForeignKey('MFavorites', on_delete=models.CASCADE, verbose_name='属于', to_field='id')
    cover = models.CharField(verbose_name='图片路径', max_length=100, default='/static/default.png')

    class Meta:
        verbose_name_plural = '小收藏夹'


class Image(models.Model):
    path = models.CharField(null=True, blank=True, verbose_name='图片路径', max_length=100)
    favorite = models.ForeignKey('SFavorites', on_delete=models.CASCADE, verbose_name='属于')
    user = models.ForeignKey('Users', on_delete=models.CASCADE)


